package com.cxhome.cxinfox.Auditing;

import com.jfinal.plugin.activerecord.Page;
import com.traffic.managent.annotation.ControllerBind;
import com.traffic.managent.base.CxBaseController;
import com.traffic.managent.model.product.Auditing;
import com.traffic.managent.model.system.User;
import com.traffic.managent.util.StringUtils;

/**
 * 审核管理
 * 
 * @author Guoxing
 *
 */
@ControllerBind(controllerKey = "/system/auditing")
public class AuditingController extends CxBaseController {

	private static final String path = "/pages/system/auditing/auditing_";

	public void index() {
		list();
	}

	/**
	 * 审核列表
	 */
	public void list() {
		Auditing model = getModelByAttr(Auditing.class);

		StringBuilder orderSql = new StringBuilder("");
		// 排序
		String orderBy = getBaseForm().getOrderBy();
		if (StringUtils.isEmpty(orderBy)) {
			orderSql.append(" order by ca.createTime desc");
		} else {
			orderSql.append(" order by ca.").append(orderBy.trim());
		}

		Page<Auditing> page = AuditingService.service.paginate(model, getPaginator(), orderSql.toString());

		setAttr("page", page);
		setAttr("attr", model);
		render(path + "list.html");
	}
//	public void list() {
//		Auditing model = getModelByAttr(Auditing.class);
//		
//		SQLUtils sql = new SQLUtils(" from cx_auditing ca where 1=1");
//		
//		if (model.getAttrValues().length != 0) {
//			sql.whereLike("status", model.getStr("status"));
//			sql.whereLike("type", model.getStr("type"));
//		}
//		
//		// 排序
//		String orderBy = getBaseForm().getOrderBy();
//		if (StringUtils.isEmpty(orderBy)) {
//			sql.append(" order by ca.createTime desc");
//		} else {
//			sql.append(" order by ca.").append(orderBy);
//		}
//		
//		Page<Auditing> page = Auditing.dao.paginate(getPaginator(), "select ca.*  ", sql.toString());
//		
//		setAttr("page", page);
//		setAttr("attr", model);
//		render(path + "list.html");
//	}

	/**
	 * 查看详情
	 */
	public void view() {
		Auditing model = Auditing.dao.findById(getPara());

		setAttr("model", model);
		render(path + "view.html");
	}

	
	/**
	 * 编辑或者保存
	 */
	public void rejectOrPass() {
		String ids = getPara().split(",")[0];
		String status = getPara().split(",")[1];
		User user = (User) getSessionUser();

		AuditingService.service.saveOrUpdate(ids, status, user);
		// 返回列表
		list();
	}

	
	
}
